08. Quiz: Murder Mystery (3-4)
Directions:
For this quiz, you're going to help solve a fictitious murder mystery that happened here at Udacity! A murder mystery is a game typically played at parties wherein one of the partygoers is secretly, and unknowingly, playing a murderer, and the other attendees must determine who among them is the criminal. It's a classic case of whodunnit.
Since this might be your first time playing a murder mystery, we've simplified things quite a bit to make it easier. Here's what we know! In this murder mystery there are:
- four rooms: the ballroom, gallery, billiards room, and dining room,
- four weapons: poison, a trophy, a pool stick, and a knife,
- and four suspects: Mr. Parkes, Ms. Van Cleve, Mrs. Sparr, and Mr. Kalehoff.
We also know that each weapon corresponds to a particular room, so…
- the
poison
belongs to theballroom
, - the
trophy
belongs to thegallery
, - the
pool stick
belongs to thebilliards room
, - and the
knife
belongs to thedining room
.
And we know that each suspect was located in a specific room at the time of the murder.
Mr. Parkes
was located in thedining room
.Ms. Van Cleve
was located in thegallery
.Mrs. Sparr
was located in thebilliards room
.Mr. Kalehoff
was located in theballroom
.
To help solve this mystery, write a combination of conditional statements that:
- sets the value of
weapon
based on theroom
and - sets the value of
solved
totrue
if the value ofroom
matches thesuspect
's room
Afterwards, use this template to print a message to the console if the mystery was solved:
__________ did it in the __________ with the __________!
What goes into the three blank spaces? You can fill in the blanks with the name of the suspect, the room, and the weapon! For example, an output string may look like:
Mr. Parkes did it in the dining room with the knife!
Be sure to watch out for any extra or missing characters (including spaces and punctuation marks) in your output string as well!
TIP: Test your code with different values. For example,
Ifroom
equalsgallery
andsuspect
equalsMs. Van Cleve
, thenMs. Van Cleve did it in the gallery with the trophy!
should be printed to the console.
Your Code:
Start Quiz:
/*
* Programming Quiz: Murder Mystery (3-4)
*/
// change the value of `room` and `suspect` to test your code
var room = "dining room";
var suspect = "Mr. Parkes";
var weapon = "";
var solved = false;
if (/* your conditional goes here */) {
} else if (/* your conditional goes here */) {
} else if (/* your conditional goes here */) {
} else {
}
if (solved) {
console.log(/* your message goes here*/);
}
INSTRUCTOR NOTE:
Have questions? Head to Knowledge for discussion with the Udacity Community.